package pri.zxx.excelgenerate.dataentity.tabledata.growth;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import pri.zxx.excelgenerate.dataentity.entity.CreatRequest;
import pri.zxx.excelgenerate.dataentity.entity.ExcelData;
import pri.zxx.excelgenerate.dataentity.entity.ModuleInfoEnum;
import pri.zxx.excelgenerate.dataentity.entity.ModuleMetaInfo;
import pri.zxx.excelgenerate.dataentity.tabledata.MultiTitleModuleCreatorTemplate;
import pri.zxx.excelgenerate.dataentity.tabledata.TableDefinition;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 总 生 长 性能 模块
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@Component
@Slf4j
public class TotalGrowthModuleCreator extends MultiTitleModuleCreatorTemplate {


    //todo 注入数据获取的bean

    @Override
    public List<ModuleMetaInfo> creator(CreatRequest creatRequest) {
        CreatRequest.TableCreateReq tcr = new CreatRequest.TableCreateReq(1.0, 2, Arrays.asList("预估值", "观测值"));
        creatRequest.setTableCreateReq(tcr);

        //模块自定义请求参数
        CreatRequest cr = new CreatRequest();
        BeanUtils.copyProperties(creatRequest, cr);
        cr.setRanges(null);

        List<ModuleMetaInfo> modules = new ArrayList<>();


        ModuleMetaInfo metaInfo = new ModuleMetaInfo();
        metaInfo.setModuleTitle(moduleInfo().getName()).setModuleInfoEnum(moduleInfo());


        TableDefinition tableDefinition = new TableDefinition();

        List<ExcelData> gss = new ArrayList<>();

        //todo 调用获取数据的service
        switch (creatRequest.getPredictionTypeEnum()) {
            case GESTATING_SOWS:
                TotalGrowthGestatingSows gs = new TotalGrowthGestatingSows();
                gss.add(gs);
                tableDefinition.setDataClass(TotalGrowthGestatingSows.class);
                break;
            case STARTING_PIGS:
            case LACTATING_SOWS:
                TotalGrowthStartingPigs sp = new TotalGrowthStartingPigs();
                gss.add(sp);
                tableDefinition.setDataClass(TotalGrowthStartingPigs.class);
                metaInfo.setModuleTitle("预估结果：生长性能");
                break;
            case GROWING_FINISHING:
                TotalGrowthGrowingFinishing gf = new TotalGrowthGrowingFinishing();
                gss.add(gf);
                tableDefinition.setDataClass(TotalGrowthGrowingFinishing.class);
                break;
            default:
                throw new RuntimeException("动物类型异常");
        }
        tableDefinition.setUnLoadData(gss);

        //组装数据
        tableDefinition = dataHandle(moduleMetaInfoHandle(tableDefinition, cr), cr);
        metaInfo.setTableDefinition(tableDefinition);

        modules.add(metaInfo);
        return modules;
    }

    @Override
    public ModuleInfoEnum moduleInfo() {
        return ModuleInfoEnum.OP_GROWTH_TOTAL;
    }

}
